/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.spoxcy.listener;

import com.spoxcy.util.DBUtil;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 *
 * @author Denis.Duan
 * @date Apr 19, 2009
 */
public class InitializationListener implements ServletContextListener {

    public void contextInitialized(ServletContextEvent sce) {

        //obtain initial database parameters from web.xml then set them into
        //dbUtility. Then save dbUtility into context
        DBUtil dbUtility = new DBUtil();
        ServletContext context = sce.getServletContext();
        dbUtility.setDb_connector(context.getInitParameter("db_connector"));
        dbUtility.setDb_url(context.getInitParameter("db_url"));
        dbUtility.setDb_username(context.getInitParameter("db_username"));
        dbUtility.setDb_password(context.getInitParameter("db_password"));

        context.setAttribute("dbUtility", dbUtility);

    }

    public void contextDestroyed(ServletContextEvent sce) {

    }

}
